#include <malloc.h>
#include "stdio.h"

struct node {
    int pos;
    float time;
};

int cmp(struct node *a, struct node *b)
{
    return (a->pos - b->pos);
}

int carFleet(int target, int *position, int positionSize, int *speed, int speedSize)
{
    int cnt = 1;
    struct node *tmp = (struct node *)malloc(positionSize * sizeof(struct node));
    for (int i = 0; i < positionSize; i++) {
        tmp[i].pos = position[i];
        tmp[i].time = (float)(target - position[i]) / speed[i];
    }
    qsort(tmp, positionSize, sizeof(struct node), (int (*)(const void *, const void *)) cmp);
    for (int i = positionSize - 1; i > 0; i--) {
        if (tmp[i].time >= tmp[i - 1].time) {
            tmp[i - 1].time = tmp[i].time;
        } else {
            cnt++;
        }
    }
    return cnt;
}

int main()
{
    int target = 12, position[5] = {10,8,0,5,3}, speed[5] = {2,4,1,1,3};
    int ret = carFleet(target, position, 5, speed, 5);
    printf("%d", ret);
}